<extend name="Public/base" />

<block name="body">
	<!-- 标题栏 -->
	<div class="main-title">
		<h2>发货详情</h2>
	</div>
	<div class="cf"></div>
    <!-- 数据列表 -->
    <div class="data-table table-striped">
    	<b>订单号：</b>{$data.order_id}
	    <form action="{:U('sendGoods')}" method="post" class="form-horizontal">
			<table class="">
		    <thead>
		        <tr>
				<th class="" colspan="5">
					<center>确认收货地址及交易详情</center>
				</th>
				</tr>
		    </thead>
		    <tbody>
				<notempty name="_list">
				<volist name="_list" id="vo">
				<tr>
					<td width="10%"><img src="{$vo.picture|get_cover='path'}" style="width:40%;"/></td>
					<td width="30%">{$vo.name}</td>
					<td width="8%">￥{$vo.price}</td>
					<td width="8%" colspan="2">数量：{$vo.num}</td>
				</tr>
				</volist>
				<tr>
					<td colspan="4">总共需支付：￥{$data.allprice}</td>
				</tr>
                <if condition="IS_ROOT and ($data['order_status'] elt 1)">
                    <tr>
                        <td>订单状态</td>
                        <td colspan="3">
                            <select name="order_status" id="order_status" disabled="">
                                <option value="0" <if condition="$data['order_status'] eq 0">selected="selected"</if>>等待买家付款</option>
                                <option value="1" <if condition="$data['order_status'] eq 1">selected="selected"</if>>付款确认中</option>
                                <option value="2" <if condition="$data['order_status'] eq 2">selected="selected"</if>>买家已付款</option>
                            </select>
                        </td>
                        <td class="update_status"><a href="javascript:void(0);" class="update">修改</a></td>
                    </tr>
                </if>
                <tr>
                    <td>默认地址</td>
                    <td colspan="4">
                        收货人：{$data.name}
                        联系电话：{$data.phone}
                        联系地址：{$data.pro_id|getAreaName=###} {$data.city_id|getAreaName=###} {$data.area_id|getAreaName=###} {$data.address}
                        邮编：{$data.code|default='无'}
                    </td>
                </tr>
                <tr>
                    <td>买家收货信息</td>
                    <td colspan="3">
                    <span class="displayTake" style="<empty name='vo.take_text'>display:none;</empty>">
                        <textarea name="take_text" id="take_text" style="width: 800px;height: 40px;line-height: 40px;">{$vo.take_text}</textarea>
                        <input type="hidden" id="order_id_old" value="{$vo.order_id}">
                    </span>
                    </td>
                    <td class="take">
                        <a href="javascript:void(0);" class="update">修改</a>
                    </td>
                </tr>
				<tr class="lianxiwuliu">
					<td>联系物流</td>
					<td colspan="5">
						<span style="<notempty name='data.type'>display:none;</notempty>" class="wuliuname">
							<label class="item-label" style="display: inline;">物流名称：</label>
							 <select name="wl_name" id="wl_name">
					            <volist name="_wulius" id="v">
					                <option value="{$v.name}" <if condition="$v['default'] eq 1">selected="selected"</if>>{$v.name}</option>          
					            </volist>
					        </select> 
					        <a href="{:U('Wuliu/index')}">设置物流</a>&nbsp; &nbsp;&nbsp;&nbsp;
					        <label class="item-label" style="display: inline;">运货单号：</label>
					        <input type="text" class="text input-large" name="wl_order" id="wl_order" value="">
					        <input type="hidden" name="order_id" id="order_id" value="{$data.order_id}">
					    </span>

						<span style="<empty name='data.type'>display:none;</empty>" class="wuliuname2">
							<label class="item-label" style="display: inline;">物流名称：{$data.wl_name|default="无"}</label>
							<label class="item-label" style="display: inline;">运货单号：{$data.wl_order|default="无"}</label>
							<label class="item-label" style="display: inline;"><a href="javascript:void(0);" class="updateWuliu">修改</a></label>
				        </span>
				        <label class="item-label" style="display: inline;"><a href="javascript:void(0);" class="wuliu">查看物流</a></label>

					</td>
				</tr>
				<empty name="data.type">
					<tr>
						<td colspan="5">
							<button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">确 定 发 货</button>
						</td>
					</tr>
				<else />
					<tr>
						<td colspan="5">
							<button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
						</td>
					</tr>
				</empty>
				<else/>
				<td colspan="4" class="text-center"> aOh! 暂时还没有内容! </td>
				</notempty>
			</tbody>
		    </table>
	    </form>
	    <!-- 物流信息开始 -->
	    <div class="wuliu_table" style="display:none;">
			<iframe name="kuaidi100" src="http://www.kuaidi100.com/chaxun?com={$data.wl_name|getCompanyCode=###}&nu={$data.wl_order}" width="960" height="880" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"></iframe>
		</div>
		<!-- 物流信息结束 -->
	</div>
</block>

<block name="script">
	<script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>

	<script type="text/javascript">
	//搜索功能
	$("#search").click(function(){
		var url = $(this).attr('url');
        var query  = $('.search-form').find('input').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
        if( url.indexOf('?')>0 ){
            url += '&' + query;
        }else{
            url += '?' + query;
        }
		window.location.href = url;
	});
	//回车搜索
	$(".search-input").keyup(function(e){
		if(e.keyCode === 13){
			$("#search").click();
			return false;
		}
	});
	//查看物流信息
	$('.wuliu').click(function(){
		$('.wuliu_table').slideToggle('slow');
	});

	$('.take').on('click', '.update', function(){
		$('.displayTake').show();
		$(this).parent().html('<a href="javascript:void(0);" class="sureAttr">确认修改</a>&nbsp;&nbsp;<a href="">返回</a>');
	}).on('click', '.sureAttr', function(){
		var order_id = $('#order_id').val(),
			take_text = $('#take_text').val();
		$.ajax({
			url: "{:U('updateTake')}",
			type: 'get',
			data: {
				order_id: order_id,
				take_text: take_text
			},
			dataType: 'json',
			beforeSend: function(){
				$(this).parent().html('请稍后...');
			},
			success: function(r){
				if(r.status){
					window.location.reload();
				}
			}
		});
	});

	$('.updateWuliu').click(function(){
		$('.wuliuname').show();
		$('.wuliuname2').hide();
		$('.wuliuname').append('<label class="item-label" style="display: inline;"><a href="javascript:void(0);" class="sureWuliuinfo">完成修改</a></label>');
	});

	$('.lianxiwuliu').on('click', '.sureWuliuinfo', function(){
		var wl_name = $('#wl_name').val(),
			wl_order = $('#wl_order').val(),
			order_id = $('#order_id').val();
        if(wl_order.length == 0){
            alert('物流单号必填！');
            return false;
        }
		$.get("{:U('updateWuliu')}", {order_id: order_id, wl_name: wl_name, wl_order: wl_order}, function(r){
			if(r.status){
				window.location.reload();
			}
		}, 'json');
	});

    //修改状态
    $('.update_status').click(function(){
        $('#order_status').removeAttr("disabled");
        $(this).html('<a href="javascript:void(0);" class="sureStatus">确认修改</a>&nbsp;&nbsp;<a href="">返回</a>');
    });

    $('.update_status').on('click', '.sureStatus', function(){
        var order_status = $('#order_status').val();
        var order_id = $('#order_id').val();
        $.get("{:U('updateStatus')}", {order_id: order_id, order_status: order_status}, function(r){
            if(r.status){
                window.location.reload();
            }
        }, 'json');
    })

    //导航高亮
    highlight_subnav('{:U('Order/index')}');
	</script>
</block>
